package com.heima.model.article.dtos;

import com.heima.model.article.pojos.ApArticle;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.model.wemedia.pojos.WmUser;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.Date;

@Data
public class ArticleDto extends ApArticle {
  /** 文章内容 */
  private String content;

  public static ArticleDto init(WmUser wmUser, WmNews wmNews, WmChannel wmChannel) {

    ArticleDto articleDto = new ArticleDto();
    BeanUtils.copyProperties(wmNews, articleDto);

    // 完善属性
    articleDto.setId(wmNews.getArticleId());
    articleDto.setTitle(wmNews.getTitle());
    articleDto.setAuthorId(Long.valueOf(wmNews.getUserId()));
    articleDto.setAuthorName(wmUser.getName());
    articleDto.setChannelId(wmNews.getChannelId());
    articleDto.setChannelName(wmChannel.getName());
    articleDto.setLayout(wmNews.getType());
    articleDto.setImages(wmNews.getImages());
    articleDto.setLabels(wmNews.getLabels());
    articleDto.setCollection(0);
    articleDto.setCreatedTime(new Date());
    articleDto.setPublishTime(new Date());

    return articleDto;
  }
}
